import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter_device_info_plugin/flutter_device_info_plugin.dart';
import 'package:furaha_mkopo/commonTool/fm_jump_tool.dart';
import 'package:furaha_mkopo/commonTool/fm_report_event_tool.dart';
import 'package:furaha_mkopo/commonTool/fm_time_tool.dart';
import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart';

class FMWebController extends GetxController {

  int startTime = 0;

  Position? position;

  void back(BuildContext context) {
    Navigator.pop(context);
  }

  void jumpWidget(BuildContext context,String message) {

    String value = extractValueFromBrackets(message);

    FMJumpTool.jumpWidget(context:context,url: value);
  }

  void backToHome(BuildContext context) {
    FMJumpTool.jumpHomeWidget();
    Navigator.pop(context);
  }

  void showSKStoreReview() {
    FlutterDeviceInfoPlugin().showSKStoreReview();
  }

  void addMobState(String message) {
    int time = FMTimeTool.currentTime;
    FMReportEventTool.reportRisk("10", position?.latitude, position?.longitude, time, time,orderId: "");
  }

  void endBindingCard() {
    int endTime = FMTimeTool.currentTime;
    FMReportEventTool.reportRisk("8", position?.latitude, position?.longitude, startTime, endTime);
  }

  String extractValueFromBrackets(String input) {
    // 使用正则表达式提取方括号内的内容
    RegExp regExp = RegExp(r'\[(.*?)\]');
    Match? match = regExp.firstMatch(input);

    return match != null ? match.group(1) ?? '' : '';
  }
}